<template>
  <div>
    <el-form :model="form" label-width="70px" style="width: 380px">
      <el-form-item label="搜索：">
        <el-input
          v-model="form.keyword"
          placeholder="请输入搜索内容"
          size="small"
          clearable
          style="width: 200px"
        ></el-input>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="small"
          @click="view"
          >搜索</el-button
        >
      </el-form-item>
    </el-form>
    <el-table
      :data="tableViewData"
      style="width: 100%"
      :header-cell-style="{ 'text-align': 'center' }"
      :cell-style="{ 'text-align': 'center' }"
    >
      <el-table-column type="index"> </el-table-column>
      <el-table-column prop="cpu" label="cpu" width="100">
        <!-- <template slot-scope="{ row }">
          <el-tag v-if="row.resourceType === '计算'" type="success"
            >计算</el-tag
          >
          <el-tag v-if="row.resourceType === '存储'" type="warning"
            >存储</el-tag
          >
        </template> -->
      </el-table-column>
      <el-table-column prop="memo" label="内存"> </el-table-column>
      <el-table-column prop="harddisk" label="硬盘" width="180">
      </el-table-column>
      <el-table-column prop="network" label="带宽(Mbps)" width="180">
      </el-table-column>
      <el-table-column
        prop="price"
        label="价格(元)"
        width="180"
      ></el-table-column>
      <el-table-column prop="discription" label="详情" width="180">
      </el-table-column>
      <el-table-column prop="ownerName" label="发布人" width="180">
      </el-table-column>
      <el-table-column prop="operation" label="操作" width="250">
        <template>
          <el-button type="success" size="mini" round>购买</el-button>
          <el-button type="primary" size="mini" round>关注</el-button>
          <el-button type="warning" size="mini" round>忽略</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="1"
      :page-sizes="[5, 10, 20, 50]"
      :page-size="10"
      layout="total, sizes, prev, pager, next, jumper"
      :total="this.tableData.length"
      style="margin-top: 20px"
    >
    </el-pagination>
  </div>
</template>

<script>
export default {
  name: "InterestList",
  mounted() {
    this.getResouceList();
  },
  data() {
    return {
      form: {
        keyword: "",
      },
      tableData: [],
      tableViewData: [],
      pageSize: 10,
      pageNum: 1,
    };
  },
  methods: {
    handleSizeChange(val) {
      this.tableViewData = [];
      this.pageSize = val;
      for (
        var i = (this.pageNum - 1) * this.pageSize;
        i < this.pageNum * this.pageSize;
        i++
      ) {
        if (this.tableData[i]) {
          this.tableViewData.push(this.tableData[i]);
        }
      }
      console.log(this.tableViewData);
    },
    handleCurrentChange(val) {
      this.tableViewData = [];
      this.pageNum = val;
      for (
        var i = (this.pageNum - 1) * this.pageSize;
        i < this.pageNum * this.pageSize;
        i++
      ) {
        if (this.tableData[i]) {
          this.tableViewData.push(this.tableData[i]);
        }
      }
      console.log(this.tableViewData);
    },
    getResouceList() {
      this.GLOBAL.web3.eth.getAccounts().then((res) => {
        this.GLOBAL.contract.methods
          .showUserFollowedResources(this.$route.query.username) //修改这个合约
          .call({ from: res[0] })
          .then((res) => {
            console.log("res99:", res);
            this.tableData = res;
            for (var i = 0; i < 10; i++) {
              if (res[i]) {
                this.tableViewData.push(res[i]);
              }
            }
          });
      });
    },
  },
};
</script>

<style>
</style>
